package com.jy.rhin.application.infra;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.jy.rhin.domain.notification.participant.entity.EnumParticipantRole;
import com.jy.rhin.facade.infra.controller.dto.ShiJianZXStatisticsDto;
import com.jy.rhin.infra.repo.notfication.participant.mapper.ParticipantMapper;
import com.jy.rhin.infra.repo.notfication.participant.po.ParticipantPO;
import com.jy.rhin.infra.repo.notfication.subscribe.mapper.SubscribeMapper;
import com.jy.rhin.infra.repo.notfication.topic.query.TopicQueryHandler;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author yuyue
 * @date 2023/9/4
 */
@Service
public class InfraStatisticsService {

    @Resource
    private ParticipantMapper participantMapper;
    @Resource
    private SubscribeMapper subscribeMapper;
    @Resource
    TopicQueryHandler topicQueryHandler;

    public ShiJianZXStatisticsDto getShiJianZXFW() {
        Integer shiJianFBZS = participantMapper.selectCount(Wrappers.<ParticipantPO>lambdaQuery()
                .eq(ParticipantPO::getParticipantRole, EnumParticipantRole.PUBLISHER));
        Integer dingYueZTS = participantMapper.selectCount(Wrappers.<ParticipantPO>lambdaQuery()
                .eq(ParticipantPO::getParticipantRole, EnumParticipantRole.SUBSCRIBER));

        Integer topicCount = topicQueryHandler.countTopic();
        Integer subscriberCount = subscribeMapper.getSubscriberCount();

        ShiJianZXStatisticsDto shiJianZXStatisticsDto = new ShiJianZXStatisticsDto();

        shiJianZXStatisticsDto.setShiJianFBZS(shiJianFBZS);
        shiJianZXStatisticsDto.setShiJianDYZS(dingYueZTS);
        shiJianZXStatisticsDto.setFaBuZTS(topicCount);
        shiJianZXStatisticsDto.setDingYueZTS(subscriberCount);

        return shiJianZXStatisticsDto;
    }




}
